import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import java.net.UnknownHostException;
 
/**
 *
 * @author Code4LifeVn
 */
public class PhoneBookRunner {
    public static void main(String[] args) throws UnknownHostException {
        PhoneBookDAO mongoDAO = new PhoneBookDAO();
 
        //SELECT ALL DOCUMENTS
        DBCursor cursor = mongoDAO.getDBCollection().find();
        while(cursor.hasNext()) {
            DBObject obj = cursor.next();
            PhoneBook model = mongoDAO.readItem(obj);
            System.out.println(model);
        }
        //INSERT A NEW DOCUMENT
        PhoneBook newPhoneBook = new PhoneBook();
        newPhoneBook.setMobi(1679997777);
        PhoneBook.UserInfo userInfo = new PhoneBook().new UserInfo();
        userInfo.setFirstName("Manh");
        userInfo.setLastName("Do");
        userInfo.setAge(23);
 
        newPhoneBook.setInfo(userInfo);
        mongoDAO.insert(newPhoneBook);
 
        //Update DOCUMENT
        PhoneBook query = new PhoneBook();
        query.setMobi(1696221490);
        PhoneBook query2 = new PhoneBook();
        query2.setMobi(1111111111);
        mongoDAO.update(query, query2);
 
        //DELETE Document
//        PhoneBook deleteObj = mongoDAO.findDocumentById("5157e080f6655c57214be159");
//        mongoDAO.delete(deleteObj);
    }
}